package com.tbit.uqbike.webmanager.controller;

import java.util.List;

import com.tbit.uqbike.object.pojo.VoiceType;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.IVoiceTypeService;
import com.tbit.uqbike.webmanager.util.ServletUtils;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 语音类型Controller
 *
 * @author zbr
 * @date 2023-11-02
 */
@RestController
@Slf4j
@RequestMapping("/voicetype")
public class VoiceTypeController extends BaseController {
    @Autowired
    private IVoiceTypeService voiceTypeService;

    /**
     * 查询语音类型列表
     */

    @PostMapping("/list")
    public JsonResult list(@RequestBody VoiceType voiceType) {
        List<VoiceType> list = voiceTypeService.selectVoiceTypeList(voiceType);
        return JsonResult.ok(list);
    }


    //查询页面
    @PostMapping("/queryPage")
    public JsonResult queryPage(@RequestBody VoiceType voiceType,
                                @RequestParam(defaultValue = "10") Integer rowCount,
                                @RequestParam(defaultValue = "1") Integer pageNO) {
        List<VoiceType> list = voiceTypeService.queryPage(voiceType, rowCount, pageNO);
        int total = voiceTypeService.queryCount(voiceType);
        return JsonResult.ok(list, total);
    }


    /**
     * 获取语音类型详细信息
     */
    @PostMapping(value = "/{voiceId}")
    public JsonResult getInfo(@PathVariable("voiceId") Integer voiceId) {

        return JsonResult.ok(voiceTypeService.selectVoiceTypeByVoiceId(voiceId));
    }

    /**
     * 新增语音类型
     */

    @PostMapping(value = "/add")
    public JsonResult add(@RequestBody VoiceType voiceType) {
        return JsonResult.toAjax(voiceTypeService.insertVoiceType(voiceType), getLogin(ServletUtils.getRequest()).context);
    }

    /**
     * 修改语音类型
     */


    @PostMapping(value = "/edit")
    public JsonResult edit(@RequestBody VoiceType voiceType) {

        return JsonResult.toAjax(voiceTypeService.updateVoiceType(voiceType), getLogin(ServletUtils.getRequest()).context);
    }

    /**
     * 删除语音类型
     */
    @PostMapping("/delete")
    public JsonResult remove(@RequestBody List<Integer> voiceIds) {


        return JsonResult.toAjax(voiceTypeService.deleteVoiceTypeByVoiceIds(voiceIds), getLogin(ServletUtils.getRequest()).context);
    }
}
